package com.xingyun.mvp.ui.home.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.widget.autolayout.AutoToolbar;
import com.xingyun.R;
import com.xingyun.app.data.entity.TodayArticleResponse;
import com.xingyun.di.component.DaggerArticleComponent;
import com.xingyun.di.module.ArticleModule;
import com.xingyun.mvp.contract.ArticleContract;
import com.xingyun.mvp.presenter.ArticlePresenter;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;


public class ArticleActivity extends BaseActivity<ArticlePresenter> implements ArticleContract.View {

    @BindView(R.id.toolbar_back)
    ImageView toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.toolbar)
    AutoToolbar toolbar;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.tv_author)
    TextView tvAuthor;

    @Override
    public void setupActivityComponent(AppComponent appComponent) {
        DaggerArticleComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .articleModule(new ArticleModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_article; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        toolbarBack.setVisibility(View.VISIBLE);
        TodayArticleResponse.DataBean dataBean = (TodayArticleResponse.DataBean) getIntent().getSerializableExtra("ArticleMsg");

        setTitle(dataBean.getTitle());
        String str_content = dataBean.getContent();
        str_content = str_content.replace("<p>", "\u3000\u3000")
                .replace("</p>", "\n");
//        toolbarTitle.setText(dataBean.getTitle());
        tvContent.setText(str_content);
        tvAuthor.setText("--- "+dataBean.getAuthor());

    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

}
